{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d78f4f5c",
   "metadata": {},
   "outputs": [],
   "source": [
    "from gs_quant.markets.index import Index, PriceType\n",
    "from gs_quant.session import Environment, GsSession\n",
    "import datetime as dt"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7fb27b941602401d91542211134fc71a",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "## Pre Requisites\n",
    "To use below functionality on **STS Indices**, your application needs to have access to the following datasets:\n",
    "1. [STSLEVELS](https://marquee.gs.com/s/developer/datasets/STSLEVELS) - Official Values of STS Indices\n",
    "2. [STS_INDICATIVE_LEVELS](https://marquee.gs.com/s/developer/datasets/STS_INDICATIVE_LEVELS) - Indicative Values of STS Indices\n",
    "\n",
    "You can request access by going to the Dataset Catalog Page linked above.\n",
    "\n",
    "Note - Please skip this if you are an internal user"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c6eff76d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# external users should substitute their client id and secret; please skip this step if using internal jupyterhub\n",
    "GsSession.use(Environment.PROD, client_id=None, client_secret=None, scopes=('read_product_data',))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3ac14d1f",
   "metadata": {},
   "outputs": [],
   "source": [
    "index = Index.get('GSXXXXXX')  # substitute input with any identifier for an index"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "97a0847c",
   "metadata": {},
   "source": [
    "#### Close price functions supports the following price types"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ad9bf45e",
   "metadata": {},
   "source": [
    "You may choose one of the following price types:\n",
    "\n",
    "- **Official Price:** PriceType.OFFICIAL_PRICE\n",
    "- **Indicative Price** PriceType.INDICATIVE_CLOSE_PRICE - Currently supports STS indices only.\n",
    "\n",
    "Default returns the official close price"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7e037f7a",
   "metadata": {},
   "outputs": [],
   "source": [
    "index.get_latest_close_price(\n",
    "    price_type=[PriceType.OFFICIAL_CLOSE_PRICE]\n",
    ")  # returns latest official levels for the index."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5e179014",
   "metadata": {},
   "outputs": [],
   "source": [
    "index.get_close_price_for_date(\n",
    "    dt.date(2021, 1, 7), price_type=[PriceType.OFFICIAL_CLOSE_PRICE]\n",
    ")  # returns official levels for a given date."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bdd5f86d",
   "metadata": {},
   "outputs": [],
   "source": [
    "index.get_close_prices(\n",
    "    start=dt.date(2021, 1, 7), end=dt.date(2021, 3, 27), price_type=[PriceType.OFFICIAL_CLOSE_PRICE]\n",
    ")  # returns official levels for a given date range."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f7f9f147",
   "metadata": {},
   "outputs": [],
   "source": [
    "index.get_close_prices(price_type=[PriceType.OFFICIAL_CLOSE_PRICE])  # returns all the official levels of the index."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b5a88445",
   "metadata": {},
   "source": [
    "#### STS indices can use PriceType.INDICATIVE_CLOSE_PRICE as well to get the indicative levels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8ceaa6e6",
   "metadata": {},
   "outputs": [],
   "source": [
    "index.get_latest_close_price(\n",
    "    price_type=[PriceType.OFFICIAL_CLOSE_PRICE, PriceType.INDICATIVE_CLOSE_PRICE]\n",
    ")  # returns latest indicative and official levels of the index."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3b129435",
   "metadata": {},
   "outputs": [],
   "source": [
    "index.get_close_price_for_date(\n",
    "    dt.date(2021, 1, 7), price_type=[PriceType.OFFICIAL_CLOSE_PRICE, PriceType.INDICATIVE_CLOSE_PRICE]\n",
    ")  # returns both indicative and official levels of the index for a given date."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "371146cb",
   "metadata": {},
   "outputs": [],
   "source": [
    "index.get_close_prices(\n",
    "    start=dt.date(2021, 1, 7),\n",
    "    end=dt.date(2021, 3, 27),\n",
    "    price_type=[PriceType.OFFICIAL_CLOSE_PRICE, PriceType.INDICATIVE_CLOSE_PRICE],\n",
    ")  # returns both indicative and official levels of the index for a given date range."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ebc1ad33",
   "metadata": {},
   "outputs": [],
   "source": [
    "index.get_close_prices(\n",
    "    price_type=[PriceType.OFFICIAL_CLOSE_PRICE, PriceType.INDICATIVE_CLOSE_PRICE]\n",
    ")  # returns all the indicative and official levels of the index."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "acae54e37e7d407bbb7b55eff062a284",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "*Have any other questions? Reach out to the [Marquee STS team](mailto:gs-marquee-sts-support@gs.com)!*"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}